//
//  CHGrideViewController.swift
//  CHSimpleUI
//
//  Created by cyptt on 2023/3/16.
//

import UIKit
import CHSimpleUI
class CHGrideViewController: UIViewController {

    
    lazy var gridView = {()-> CHGridView in
        let view:CHGridView = CHGridView.init(rowMaxCount: 4, itemSpacing: 16, lineSpacing: 14)
        view.backgroundColor = UIColor.white

        return view
    }()
    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.backgroundColor = UIColor.white
        
        
        
        
        self.view.addSubview(self.gridView)
        
        var dataSources:[CHGridModel] = []
        for i in 0...30{
            let model = CHGridModel()
            model.title = "第" + String(i)
            model.iconImage =  UIImage.init(named: "juanxin_icon")
        
            model.margin = 20
            dataSources.append(model)
            
            model.cellHandelr = { cell in
                cell?.layer.backgroundColor = UIColor.red.cgColor
                cell?.layer.cornerRadius = 13
                cell?.layer.masksToBounds = true
            }
        }
        
        
        self.gridView.setDataSource(gridModels: dataSources)
      
      
    
        self.gridView.itemClickCallBack { index, gridModel in
            
            dataSources.remove(at: 0)
            self.gridView.setDataSource(gridModels: dataSources)
            self.gridView.reloadData()
        }
        
        
     
        self.gridView.snp.makeConstraints { make in
            make.width.equalToSuperview()
            make.bottom.equalTo(0)
            make.left.equalTo(0)
            make.top.equalTo(100)
        }
    }


}

